package com.jiangkai.common.shiro;

import org.apache.log4j.Logger;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;

public class TestShiro {

	
	private  final static Logger log = Logger.getLogger(TestShiro.class);
	
	public static void main(String[] args){
		log.info("开始测试！");
		
		//1,获取安全管理器
		Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiro-web.ini");
		SecurityManager securityManager = factory.getInstance();
		//2,设置安全管理器
		SecurityUtils.setSecurityManager(securityManager);
		//3 获取Subject对象，即登录的用户
		Subject currentUser = SecurityUtils.getSubject();
		Session session = currentUser.getSession();
		session.setAttribute("name", "jiangkai");
		
		String name = (String) session.getAttribute("name");
		log.info("name:"+name);
	}
	
}
